package com.hanson.service;

import com.hanson.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 合并用户
 */
@Service
public class MergeUserService {
    @Autowired
    private AcctbkSeqBeanMapper acctbkSeqBeanMapper;
    @Autowired
    private ApplyInfoBeanMapper applyInfoBeanMapper;
    @Autowired
    private CartBeanMapper cartBeanMapper;
    @Autowired
    private GoodsCollectBeanMapper goodsCollectBeanMapper;
    @Autowired
    private GoodsCommentBeanMapper goodsCommentBeanMapper;
    @Autowired
    private OrderBeanMapper orderBeanMapper;
    @Autowired
    private ScoreSeqBeanMapper scoreSeqBeanMapper;
    @Autowired
    private SpreadInfoBeanMapper spreadInfoBeanMapper;
    @Autowired
    private UserAddresBeanMapper userAddresBeanMapper;
    @Autowired
    private UserShareBeanMapper userShareBeanMapper;
    @Autowired
    private WeiXinNotifyBeanMapper weiXinNotifyBeanMapper;
    @Autowired
    private UserBeanMapper userBeanMapper;

    @Transactional(rollbackFor = Exception.class)
    @Async
    public void mergeUser(String openId, String mpOpenId,Integer oldId) {
        acctbkSeqBeanMapper.updateOpenId(mpOpenId, openId);
        applyInfoBeanMapper.updateOpenId(mpOpenId, openId);
        cartBeanMapper.updateOpenId(mpOpenId, openId);
        goodsCollectBeanMapper.updateOpenId(mpOpenId, openId);
        goodsCommentBeanMapper.updateOpenId(mpOpenId, openId);
        orderBeanMapper.updateOpenId(mpOpenId, openId);
        scoreSeqBeanMapper.updateOpenId(mpOpenId, openId);
        spreadInfoBeanMapper.updatePOpenId(mpOpenId, openId);
        spreadInfoBeanMapper.updateCOpenId(mpOpenId, openId);
        userAddresBeanMapper.updateOpenId(mpOpenId, openId);
        userShareBeanMapper.updateOpenId(mpOpenId, openId);
        weiXinNotifyBeanMapper.updateOpenId(mpOpenId, openId);
        if(null != oldId){
            userBeanMapper.updateOldSync(1,oldId);
        }
    }
}
